fix(android): prevent crash when Promise.reject is called with null error code#1325
Open
ivannikcevicc wants to merge 1 commit intodotintent:masterfrom
Open
fix(android): prevent crash when Promise.reject is called with null error code#1325ivannikcevicc wants to merge 1 commit intodotintent:masterfrom
ivannikcevicc wants to merge 1 commit intodotintent:masterfrom
Conversation
Previously, SafePromise.reject would call React Native's Promise.reject with a null 'code' parameter, causing a NullPointerException on Android.
This commit ensures that all reject methods provide a non-null fallback code ('UNKNOWN_ERROR') and message if any argument is null, preventing crashes when BLE operations fail without an explicit error code.
Also preserves atomic isFinished logic to prevent multiple resolve/reject calls.
|
run into this issue and implemented this fix, now everything works correctly 👍 |
Author
|
@theburke9 Glad to hear, I hope it gets implemented. Some people tried to fix the issue by changing the way SafePromise is called in some instances, yet I'm the only one whose issue actually fixes the SafePromise class itself. But unfortunately, It seems this repo is poorly maintained. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix: Prevent Android crash when BLE disconnect error has null error code
Summary
This PR fixes a fatal Android crash that occurs when
Promise.reject()is called with a null error code during BLE disconnect flows.On Android,
RxAndroidBleemits aBleDisconnectedExceptionfor both expected and unexpected disconnects. In some cases, the propagated error does not contain a non-null error code, which violates React Native'sPromise.rejectcontract and results in aNullPointerException.This change ensures a safe fallback error code is always provided.
Problem
During normal BLE lifecycle events (navigation cleanup, explicit disconnect, device power loss), the app may crash with:
This crash occurs even when the disconnect is expected and properly handled in JavaScript.
Root Cause
SafePromise.reject(...)forwards a nullablecodevalue intoPromise.reject(code, ...).React Native requires
codeto be non-null, which causes a runtime crash.Solution
Provide a defensive fallback error code when
codeis null before callingPromise.reject.Example:
Impact